<?php

namespace App\Admin\Renderable;

use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;
use App\Models\CaseBatch;
use App\Models\CaseContract;
use App\Models\CaseCustomer;

class CaseBatchTable extends LazyRenderable
{
    public function grid(): Grid
    {
        // 获取外部传递的参数
        $id = $this->id;

        return Grid::make(new CaseBatch(), function (Grid $grid) {
            $grid->column('number','委托批次号');
            $grid->column('case_contract_id','所属合同')->display(function($case_contract_id) {
                return CaseContract::find($case_contract_id)->title;
            });
            $grid->column('case_customer_id','所属客户')->display(function($case_customer_id) {
                return CaseCustomer::find($case_customer_id)->name;
            });
            $grid->column('created_at');

            $grid->quickSearch(['id', 'case_contract_id', 'case_customer_id']);
            $grid->model()->orderBy('id', 'desc');
            $grid->paginate(10);
            $grid->disableActions();

        });
    }
}
